package com.gome.gop.common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.cxf.binding.soap.interceptor.SoapInterceptor;
import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;

/**
 *  调用DRG加密工具
 * @author jiayongbin
 * @Date   2018.09.28
 */
public class DrgUtils {
    
	    public static WarehouseWebService getWarehouseWebService() {
			// 以下和服务端配置类似
			Map<String, Object> outProps = new HashMap<String, Object>();
			outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
			outProps.put(WSHandlerConstants.USER, "MANTONGJIEKOU");
			outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
			// 指定在调用远程ws之前触发的回调函数WsClinetAuthHandler，其实类似于一个拦截器
			outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, WsClinetAuthHandler.class.getName());
			List<SoapInterceptor> list = new ArrayList<SoapInterceptor>();
			// 添加cxf安全验证拦截器，必须
			list.add(new SAAJOutInterceptor());
			list.add(new WSS4JOutInterceptor(outProps));
	
			JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
			// 注入拦截器，用于加密安全验证信息
			factory.getOutInterceptors().addAll(list);
			// WebServiceSample服务接口
			factory.setServiceClass(WarehouseWebService.class);
			// 设置ws访问地址
			factory.setAddress("http://10.115.2.149:8080/Web/webservices/WarehouseWebService?wsdl");//125.254.128.245    UAT  http://10.115.2.149:8080
	//		factory.setAddress("http://10.58.192.74:8080/Web/webservices/WarehouseWebService"); //PRD
	//		factory.setAddress("http://127.0.0.1:8080/Web/webservices/WarehouseWebService");
	
			return (WarehouseWebService) factory.create();
		}
}
